package com.example.lots_of_demo.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.lots_of_demo.model.User;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @author : LZJ
 * @description : code for LZJ
 * @date : 2021/2/11
 */
public interface UserDao extends BaseMapper<User> {

    /**
     * 根据用户ID查找资源
     * @param id 用户ID
     * @return List<String>
     */
    @Select("SELECT concat('RES_',R.`CODE`) as id FROM `USER` U LEFT JOIN R_USER_ROLE RUR ON U.ID = RUR.USER_ID " +
            "LEFT JOIN R_ROLE_PERMISSION RRP ON RUR.ROLE_ID = RRP.ROLE_ID " +
            "LEFT JOIN R_PERMISSION_RES RPR ON RRP.PERMISSION_ID =  RPR.PERMISSION_ID " +
            "LEFT JOIN RES R ON R.ID = RPR.RES_ID " +
            "WHERE U.ID = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
    })
    Set<String> selectUserPermissions(Long id);

}
